<?php

namespace mpend\modules\cms\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\cms\models\ArticleLikeForm;
use mpend\modules\cms\models\ArticleShieldForm;

/**
 * 资讯扩展类接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class ExtendController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['POST'],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * 屏蔽文章
     * {@inheritdoc}
     */
    public function actionShield() {
        $model = new ArticleShieldForm();
        $model->user_id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::warning('屏蔽失败');
        }
        return $model->save();
    }

    /**
     * 点赞
     * @return boolean
     */
    public function actionLike() {
        $model = new ArticleLikeForm();
        $model->user_id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            return $model->dumpError('点赞请求失败，请检查传入参数有效性');
        }
        return $model->save();
    }

}
